Local gauge invariance is the principle that the action is invariant under a symmetry transformation whose parameter is an arbitrary function of spacetime, \(\alpha=\alpha(x)\), rather than a constant. Demanding this promotes a global internal symmetry to a local one and, remarkably, forces the existence of gauge fields — the photon in QED and the gluons in QCD.
The free quark Lagrangian \(\mathcal{L}=\overline\psi\,i\gamma^\mu\partial_\mu\psi\) is invariant under a global color rotation \(\psi\to g\,\psi\) with \(g=e^{i\alpha^a T^a}\) constant. If instead \(g=g(x)\) depends on position, the derivative spoils invariance because it also hits the parameter:
The second term is the obstruction to be cured.
One repairs invariance by introducing a gauge field \(A_\mu = A_\mu^a T^a\) and replacing \(\partial_\mu\) by the covariant derivative
demanding that \(A_\mu\) transform inhomogeneously,
so that the covariant derivative transforms homogeneously like the field itself:
Then the combination \(\overline\psi\,i\gamma^\mu D_\mu\psi\) is exactly invariant. The geometric meaning is that \(A_\mu\) is a connection that tells us how to parallel-transport the color frame from point to point; the comparator \(U(y,x)\) of Continuum QCD implements this transport.
The great economy of the gauge principle is that the form of the interaction is not put in by hand: once \(\partial_\mu\to D_\mu\), the coupling \(g\,\overline\psi\gamma^\mu A_\mu\psi\) between matter and gauge field is completely determined by the single constant \(g\). The abelian case (U(1)) gives QED; the non-abelian case \(SU(3)_c\) gives QCD, where the gauge field additionally self-interacts.